package cn.tedu._07article.controller;

import cn.tedu._07article.base.response.JsonResult;
import cn.tedu._07article.base.response.StatusCode;
import cn.tedu._07article.mapper.UserMapper;
import cn.tedu._07article.pojo.dto.ArticleParam;
import cn.tedu._07article.pojo.dto.UsernamePa;
import cn.tedu._07article.pojo.vo.LoginVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/v1/user/")
@Tag(name = "用户模块")
public class UserController {
    @Autowired
    private UserMapper mapper;
    @PostMapping("login")
    @Operation(description = "登录")
    @ApiOperationSupport(order = 10)
    public JsonResult login(@RequestBody UsernamePa up)
    {
        LoginVO loginVO = mapper.userlogin(up);
        if(loginVO==null)
            return new JsonResult(StatusCode.USERNAME_PASSWORD_ERROR);
        return JsonResult.ok();
    }

    @PostMapping("article")
    @Operation(description = "发布文章")
    @ApiOperationSupport(order = 20)
    public JsonResult article(@RequestBody @Validated ArticleParam param,HttpSession session)
    {

        int x=mapper.post(param);
        return JsonResult.ok();
    }
}








